package main

import (
	"fmt"
	"path"
	"runtime"
	"time"
)

//封装打印消息
type LogData struct {
	Message  string //消息
	TimeStr  string //时间戳
	LevelStr string //级别
	FileName string //文件名
	FuncName string //方法名
	LineNo   int //行号
}

func GetLineInfo() (fileName, funcName string, lineNo int) {
	pc, file, line, ok := runtime.Caller(3)
	if ok {
		fileName = file
		funcName = runtime.FuncForPC(pc).Name()
		lineNo = line
	}
	return
}

func MsgInfo(level int, format string, args ...interface{})*LogData{
	nowStr := time.Now().Format("2006-01-02 15:04:05.999")
	levelStr := LogLevelString(level)
	fileName, funcName, lineNo := GetLineInfo()
	fileName = path.Base(fileName)
	funcName = path.Base(funcName)
	msg := fmt.Sprintf(format,args)

	return &LogData{
		Message: msg,
		TimeStr: nowStr,
		LevelStr: levelStr,
		FileName: fileName,
		FuncName: funcName,
		LineNo: lineNo,
	}
}

